home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / CRS / crs53.d81 / 28may87s.pma / CXEXT.ASM < prev    next >
Assembly Source File  |  1979-12-31  |  10KB  |  578 lines

  1. ;
  2. ;
  3.     title    'C128 external Disk drive support  28 Apr 86'
  4.  
  5. ;
  6. ;    This program contains the stubs for bringing up the C128 CP/M
  7. ;    for the first time.
  8. ;
  9. ;    The method used to stub the system I/O is to send the
  10. ;    operation request to the serial port as a command and
  11. ;    recieve responce from the serial channel.
  12. ;
  13. ;    The commands supported are:
  14. ;
  15. ;    CMD:    'I'    ; input keyboard char
  16. ;    RSP:    xx    ; returns keybord char or 00 if none
  17. ;
  18. ;    CMD    'O'xx    ; send char xx to display 
  19. ;    RSP:    xx    ; echo character
  20. ;
  21. ;    CMD:    Rttss    ; read sector of data  adr by track (tt) sector (ss) 
  22. ;    RSP:    xx..yy    ; returns 128 bytes of data plus a check sum
  23. ;
  24. ;    CMD:    Wttssxx..yy    ; write sector of data, sent with a check sum 
  25. ;                ; to (xx..yy) adr by track (tt) sector (ss)
  26. ;    RSP:    xx        ; xx=00 if no error
  27. ;
  28.     page
  29.  
  30.     maclib    cpm3
  31.  
  32.     maclib    z80
  33.  
  34.     maclib    cxequ
  35.  
  36.  
  37.  
  38.     public    ?int65,?in65,?ins65,?out65,?outs65
  39.     extrn    ?intbd
  40.  
  41. ; Utility routines in standard BIOS
  42.     extrn    ?pmsg        ; print message @<HL> up to 00
  43.                 ; saves <BC> & <DE>
  44.     extrn    ?pdec        ; print binary number in <A> from 0 to 99.
  45.     extrn    ?pderr        ; print BIOS disk error header
  46.     extrn    ?conin,?cono    ; con in and out
  47.     extrn    ?const        ; get console status
  48.  
  49. ;
  50. ;    drive table
  51. ;
  52.     public    @dtbl
  53.     extrn    cmdsk0,cmdsk1,cmdsk2,cmdsk3,cmdsk4,RMdsk
  54.  
  55.     page
  56. ;
  57. ;    DRVTBL.ASM        
  58. ;
  59.     CSEG        ; place code in common memory
  60.  
  61. @dtbl:
  62.     dw    cmdsk0            ;* drive A 1541/1571 
  63.     dw    cmdsk1            ;* drive B 1541/1571
  64.     dw    cmdsk2            ;* drive C 1541/1571
  65.     dw    cmdsk3            ;* drive D 1541/1571
  66.     dw    cmdsk4            ;* drive E shares drive A
  67.     dw    0            ;* drive F 
  68.     dw    0            ;* drive G
  69.     if    EXTSYS
  70.     dw     @fdsd0            ;* drive H (external RS232)
  71.     else
  72.     dw    0            ;* drive H
  73.     endif
  74.     dw    0            ;* drive I
  75.     dw    0            ;* drive J
  76.     dw    0            ;* drive K
  77.     dw    0            ;* drive L
  78.     dw    RMdsk            ;* drive M  Memory Disk (RAM disk)
  79.     dw    0            ;* drive N
  80.     dw    0            ;* drive O
  81.     dw    0            ;* drive P
  82.  
  83.  
  84.     if    EXTSYS
  85.     CSEG
  86. ;
  87. ; Extended Disk Parameter Headers (XPDHs)
  88. ;
  89.     dw    fd$write
  90.     dw    fd$read
  91.     dw    fd$login
  92.     dw    fd$init
  93.     db    0        ; relative drive zero
  94.     db    0        ; format type byte
  95. @fdsd0:    
  96.     dph    sk128sssd,dpb$8$sssd
  97.  
  98.  
  99. ;
  100. ; DPB FOR 8 IBM 3740 format        ( 243K )
  101. ;
  102. dpb$8$sssd:    dpb    128,26,77,1024,64,2
  103.  
  104. sk128sssd:
  105.     skew    26,6,1
  106.  
  107.  
  108.  
  109.  
  110.     page
  111. ;
  112. ;    send an illegial command, should get a period back, meaning
  113. ;    that the the command was bad. at this point extrnal system
  114. ;    is ready to receive a valid command.
  115. ;
  116.     CSEG
  117. resync:
  118.     mvi    c,0dh
  119.     call    send$c
  120.     call    get
  121.     cpi    '.'
  122.     jrnz    resync
  123.  
  124.     mvi    c,'O'
  125.     call    send$c
  126.     mvi    c,07            ; beep the bell
  127.     call    send$c
  128.     call    get            ; should be a bell code
  129.     cpi    07
  130.     rz
  131.  
  132.     call    get
  133.     jr    resync
  134.  
  135.  
  136.  
  137. ;
  138. ;    CXDISK.ASM
  139. ;
  140.  
  141. ;
  142. ;
  143. ;
  144.     dseg
  145. fd$read:
  146.     mvi    a,10
  147.     sta    error$count        ; set retrys to 10
  148. retry$read:
  149.     lxi    h,retry$read
  150.     push    h            ; save retry address on the stack
  151.     mvi    a,'R'
  152.     call    set$up$dsk        ; send command, track and sector
  153. read$loop:
  154.     call    get
  155.  
  156.    if    banked
  157.     call    put$byte$de$bank    ; save byte disk bank
  158.     mov    a,c
  159.    else
  160.     mov    m,a
  161.    endif
  162.  
  163.     inx    h
  164.     call    do$sum
  165.     jrnz    read$loop
  166.  
  167.     call    get
  168.     lda    check$sum
  169.     cmp    c
  170.     jrnz    dsk$error
  171.  
  172.     pop    h            ; remove retry address
  173.     xra    a            ; A=0 (no errors)
  174. ;
  175. ;
  176. fd$init:
  177. fd$login:
  178.     ret
  179.  
  180.  
  181. ;
  182. ;
  183. ;
  184.    if    banked
  185.  
  186.     cseg
  187. put$byte$de$bank:
  188.     lda    force$map        ; read current MMU configuration
  189.     stax    d            ; force to preconfig reg adr in DE
  190.     mov    m,c            ; save C in proper bank
  191.     sta    force$map        ; force the old bank back
  192.     ret
  193.    endif
  194.  
  195.     page
  196. ;
  197. ;
  198. ;
  199.     dseg
  200. dsk$error:
  201.     call    resync
  202.     lda    error$count
  203.     dcr    a
  204.     sta    error$count
  205.     rnz                ; return to retry address
  206.  
  207.     inr    a            ; A=1 if hard error
  208.     pop    h            ; remove retry address on error
  209.     ret
  210.  
  211. error$count:    db    0
  212.  
  213.     page
  214. ;
  215. ;
  216. ;
  217.     dseg
  218. fd$write:
  219.     mvi    a,10
  220.     sta    error$count        ; set retrys to 10
  221.  
  222. retry$write:
  223.     lxi    h,retry$write
  224.     push    h
  225.     mvi    a,'W'
  226.     call    set$up$dsk        ; send command, track and sector
  227.  
  228. write$loop:
  229.    if    banked
  230.     call    get$byte$de$bank
  231.    else
  232.     mov    c,m
  233.    endif
  234.     call    send$c            ; leaves sent char in A
  235.     inx    h
  236.     call    do$sum
  237.     jrnz    write$loop
  238.     lda    check$sum
  239.     call    send$a
  240.     call    get
  241.     ora    a            ; A=0 if no errors
  242.     jrnz    dsk$error
  243.  
  244.     pop    h            ; remove error address
  245.     ret                ; A=0 (no errors)
  246.  
  247.  
  248.    if    banked
  249.  
  250.     cseg
  251. get$byte$de$bank:
  252.     lda    force$map        ; read current MMU configuration
  253.     stax    d            ; set current disk bank (in DE)
  254.     mov    c,m
  255.     sta    force$map        ; write current MMU conf back
  256.     ret
  257.    endif
  258.  
  259.     page
  260. ;
  261. ;    compute check sum and adjust byte count
  262. ;    
  263.     dseg
  264. do$sum:
  265.     mov    b,a
  266.     lda    check$sum        ; get the current sum
  267.     add    b            ; add in new byte
  268.     sta    check$sum        ; save new sum
  269.     lda    count            ; get byte count
  270.     dcr    a            ; one less to get
  271.     sta    count            ; save for later
  272.     ret                ; zero flag set if DONE
  273.  
  274. check$sum:    db    0
  275. count:        db    0
  276.  
  277.  
  278. ;
  279. ;    send the command, track and sector to the external system
  280. ;    set count to 128 bytes, clear the checksum and set HL to
  281. ;    the DMA address
  282. ;
  283. set$up$dsk:
  284.     call    send$a        ; send the comand
  285.     lda    @trk
  286.     call    send$a        ; send the track
  287.     lda    @sect
  288.     call    send$a        ; send the sector
  289.     xra    a
  290.     sta    check$sum
  291.     mvi    a,80h
  292.     sta    count        ; transfer 128 bytes
  293.     lhld    @dma        ; HL = current DMA address
  294.  
  295.    if    banked
  296.     lxi    d,bank$0    ; start by pointing to bank 0
  297.     lda    @dbnk        ; get the current disk I/O bank
  298.     ora    a        ; is it set to bank 0
  299.     rz            ; yes, return
  300.  
  301.     inx    d        ; no, point to bank 1
  302.    endif
  303.     ret
  304.  
  305.     page
  306. ;==========================================================
  307. ;        CHARACTOR INITILIZATION ROUTINES
  308. ;==========================================================
  309. ;
  310. ;
  311. ;
  312.     dseg
  313.  
  314. ;
  315. ;    set external system com rate to 19.2 K baud
  316. ;
  317. ?int65:
  318. init$ext:
  319.     lhld    usart$adr
  320.     mov    b,h
  321.     mov    c,l
  322.     inx    b
  323.     inx    b            ; point to command reg
  324.  
  325.     mvi    a,cmd$init
  326.     outp    a
  327.     inx    b            ; point to control reg
  328.     mvi    a,cntr$init$19200    ; baud rate equ 19200
  329.     outp    a
  330.  
  331.     dcx    b            ; (02)
  332.     dcx    b            ; (01)
  333.     inp    a            ; read status
  334.     dcx    b            ; (00)
  335.     inp    a            ; read hung data
  336.     ret
  337.  
  338.     page
  339. ;==========================================================
  340. ;        CHARACTOR INPUT ROUTINES
  341. ;==========================================================
  342.  
  343. ;
  344. ;
  345. ;
  346.     dseg
  347. ?in65:            ╗ characte≥ input
  348.     call    ?ins65        ; check for character adv.
  349.     jrz    ?in65        ; loop if NOT
  350.     lda    key        ; get the key code
  351.     push    psw        ; save on stack
  352.     xra    a        ; clear key
  353.     sta    key
  354.     pop    psw        ; recover current key
  355.     ret
  356.  
  357.     page
  358.  
  359. ;==========================================================
  360. ;    CHARACTER DEVICE INPUT STATUS
  361. ;==========================================================
  362.  
  363. ;
  364. ;
  365. ;
  366.     dseg
  367. ?ins65:            ; character input status
  368.     lda    key        ; is there already a key
  369.     ora    a
  370.     jrnz    ret$true    ; yes, return true
  371.     mvi    a,'I'        ; no, test if any typed
  372.     call    send$a
  373.     call    get        ; get key
  374.     ora    a        ; =0 if none
  375.     rz            ; return character not advaliable
  376.  
  377.     sta    key        ; was one, save in key 
  378. ?outs65:
  379. ret$true:
  380.     ori    0ffh
  381.     ret
  382.  
  383. key:    db    0
  384.  
  385.     page
  386. ;==========================================================
  387. ;    CHARACTER DEVICE OUTPUT
  388. ;==========================================================
  389.  
  390. ; the charactor to be output is in the C register
  391.  
  392. ;
  393. ;
  394. ;
  395.     dseg
  396. ?out65:                ; character output
  397.     mov    a,c
  398.     push    psw
  399.     mvi    a,'O'
  400.     call    send$a
  401.     pop    psw
  402.     call    send$a
  403. ;    jmp    get
  404.  
  405. ; fall thru to GET
  406.  
  407. ;==========================================================
  408. ;        EXTERNAL DEVICE LOW LEVEL DRIVERS
  409. ;==========================================================
  410.  
  411. ;
  412. ;
  413. ;
  414.     dseg
  415. get:
  416.     call    in$stat
  417.     jrz    get
  418.     dcx    b        ; point to data reg (RxD)
  419.     inp    a
  420.     mov    c,a
  421.     ret
  422. ;
  423. ;
  424. ;
  425. send$c:
  426.     mov    a,c
  427. send$a:
  428.     push    psw        ; save the character to be output
  429. send$loop:
  430.     call    out$stat
  431.     jrz    send$loop
  432.     pop    psw
  433.     dcx    b        : point to data register (TxD)
  434.     outp    a
  435.     ret
  436. ;
  437. ;
  438. ;
  439. in$stat:
  440.     lhld    usart$adr
  441.     mov    b,h
  442.     mov    c,l
  443.     inx    b        ; point to status register
  444.     inp    a
  445.     ani    rxrdy
  446.     ret
  447. ;
  448. ;
  449. ;
  450. out$stat:
  451.     lhld    usart$adr
  452.     mov    b,h
  453.     mov    c,l
  454.     inx    b        ; point to status register
  455.     inp    a
  456.     ani    txrdy
  457.     ret
  458.     else
  459. ;==========================================================
  460. ;        CHARACTOR INITILIZATION ROUTINES
  461. ;==========================================================
  462. ;
  463. ;
  464. ;
  465.     dseg
  466. ;
  467. ;    set com rate to value in ?int$bd
  468. ;    (may need to change rate if not supported)
  469. ?int65:
  470. init$ext:
  471.    if    use$6551
  472. ;
  473. ;    must gate 6551 to user port
  474. ;    this is done by init'ing the out data to an input
  475. ;    and then setting DTR
  476. ;
  477.      lxi    b,CIA2+data$dir$a
  478.     inp    a
  479.     ori    100b            ; make TxD bit (2) an input
  480.     outp    a
  481.   endif
  482.  
  483.     lhld    usart$adr
  484.     mov    b,h
  485.     mov    c,l
  486.     inx    b            ; point to status reg
  487.     outp    a            ; software reset (wr to stat reg)
  488.  
  489.     inx    b            ; point to Command register
  490.     mvi    a,cmd$init        ; set DTR active
  491.     outp    a
  492.  
  493.     inx    b            ; point to Control register
  494.     lda    ?int$bd            ; get 6551 baud rate
  495.     ori    10h            ; use baud rate generator
  496.     outp    a            ; 1 stop (7=0), 8 bits (65=0)
  497.     ret
  498.  
  499.     page
  500. ;==========================================================
  501. ;        CHARACTOR INPUT ROUTINES
  502. ;==========================================================
  503.  
  504. ;
  505. ;
  506. ;
  507.     dseg
  508. ?in65:            ╗ characte≥ input
  509.     call    ?ins65
  510.     jrz    ?in65
  511.     dcx    b        ; point to data reg
  512.     inp    a
  513.     ret
  514.  
  515. ;==========================================================
  516. ;    CHARACTER DEVICE INPUT STATUS
  517. ;==========================================================
  518. ;
  519. ;
  520. ;
  521.     dseg
  522. ?ins65:            ; character input status
  523.     lhld    usart$adr
  524.     mov    b,h
  525.     mov    c,l
  526.     inx    b        ; point to status register
  527.     inp    a
  528.     ani    rxrdy
  529.     rz
  530.     ori    -1
  531.     ret
  532.  
  533.  
  534. ;==========================================================
  535. ;    CHARACTER DEVICE OUTPUT
  536. ;==========================================================
  537.  
  538. ; the charactor to be output is in the C register
  539.  
  540. ;
  541. ;
  542. ;
  543.     dseg
  544. ?out65:                ; character output
  545.     mov    a,c
  546.     push    psw
  547.     call    ?outs65
  548.     jrz    ?out65
  549.     pop    psw
  550.     dcx    b        ; point to data register
  551.     outp    a
  552.     ret
  553.  
  554. ;==========================================================
  555. ;    CHARACTER DEVICE OUTPUT STATUS
  556. ;==========================================================
  557. ;
  558. ;
  559. ;
  560.     dseg
  561. ?outs65:            ; character input status
  562.     lhld    usart$adr
  563.     mov    b,h
  564.     mov    c,l
  565.     inx    b        ; point to status register
  566.     inp    a
  567.     ani    txrdy
  568.     rz
  569.     ori    -1
  570.     ret
  571.  
  572.  
  573.     endif
  574.  
  575.  
  576.     end
  577.  
  578.